<?php
error_reporting( E_ALL );
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
require_once('../lib/simple_pagination.php');

class TestPagination extends UnitTestCase
{
	function testLimit ()
	{
		$p = $this->getOb();
		$this->assertBounds( $a = $p->getPageBounds ( 0 ), 0, 0 );	
		$this->assertBounds( $a = $p->getPageBounds ( 1 ), 0, 29 );	
		$this->assertBounds( $a = $p->getPageBounds ( 2 ), 30, 59 );	
	}
	function testCount()
	{
		$p = $this->getOb( 10, 30 );
		$this->assertEqual( 1, $p->count() );
		
		$p = $this->getOb( 30, 30 );
		$this->assertEqual( 1, $p->count() );
		
		$p = $this->getOb( 31, 30 );
		$this->assertEqual( 2, $p->count() );
	}
	function testPageListing ()
	{
		$p = $this->getOb();
		$expectedResult = array ( 1, 2, 3, 4 );
		$this->assertEqual( $p->getPagesList() , $expectedResult );
	}
	function assertBounds ( $bounds,  $min, $max )
	{
		$this->assertIsA( $bounds, 'array' );
		$this->assertEqual( $min, $bounds[ 'min' ] );
		$this->assertEqual( $max, $bounds[ 'max' ] );
	}
	function getOb ( $total = null, $rpp = null )
	{
		if ( is_null( $total )) $total = 100;
		if ( is_null( $rpp )) $rpp = 30;
		return new SimplePagination( $total, $rpp );
	}
}

$test = &new TestPagination();
$test->run(new HtmlReporter());

?>